package com.shujia.flink.tf;

import org.apache.flink.api.common.typeinfo.Types;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

public class Demo01KeyBy {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();


        DataStreamSource<String> socketDS = env.socketTextStream("master", 8888);

//        socketDS.print(); // 没有keyBy，数据以轮询的方式发送到下游
        // keyBy之后的数据中相同的key会进入同一个线程中被处理
        // Flink会给每一个Key单独维护一个状态
        socketDS.keyBy(w -> w, Types.STRING).print();

        env.execute();


    }
}
